#include <QtGui/QApplication>
#include <QTranslator>
#include <QLocale>

#include "mainwindow.h"
#include "proto_unit.h"
#ifdef WIN32
    #include <winsock2.h>
    #include <windows.h>
    #include <winbase.h>
    #include <winnt.h>
#else
    #include <fcntl.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <unistd.h>
#endif


MainWindow * w;
CLIENTPROT * clnp;


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTranslator myTranslator;
    myTranslator.load("qinetaccess_"+QLocale::system().name(), ":/translations");
    a.installTranslator(&myTranslator);

    QTranslator qtTranslator;
    qtTranslator.load("qt_"+QLocale::system().name(), ":/translations");
    a.installTranslator(&qtTranslator);

    a.setQuitOnLastWindowClosed(false);

    w = new MainWindow();

    clnp = new CLIENTPROT(inet_addr(w->settings.serverIP.toAscii().data()), w->settings.serverPort);

    QObject::connect(clnp, SIGNAL(callBackFn(int)), w, SLOT(Foo(int)));
    QObject::connect(clnp, SIGNAL(callBackInfoFn(const char*,int,int,int)), w, SLOT(ShowMessage(const char*,int,int,int)));
    QObject::connect(clnp, SIGNAL(callBackDirNameFn(const string16*,int)), w, SLOT(SetDirName(const string16*,int)));

    w->setClientProt(clnp);

    w->show();
    if (w->settings.autoconn)
    {
        w->connectToServer();
    }
    return a.exec();
}
